<?php
use think\Session;
use think\Db;
$userType=Db::name('love_admin_user')->where(['id'=>Session::get('yoshop_admin')['user']['id']])->value('type');

?>
<div class="row">
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
        <div class="widget am-cf">
            <div class="widget-head am-cf">
                <div class="widget-title am-cf">人员列表</div>
            </div>
            <div class="widget-body am-fr">

                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="page_toolbar am-margin-bottom-xs am-cf">
                        <div class="am-form-group">
                            <?php if ($userType==1): ?>
                                <div class="am-btn-toolbar">
                                    <div class="am-btn-group am-btn-group-xs">
                                        <a class="am-btn am-btn-default am-btn-success am-radius"
                                           href="<?= url('agent.agent/add') ?>">
                                            <span class="am-icon-plus"></span> 新增
                                        </a>
                                    </div>
                                </div>
                            <?php endif; ?>
                            <form class="toolbar-form" action="" >
                                <input type="hidden" name="s" value="/<?= $request->pathinfo() ?>">
                                <div class="am-form-group am-fl" style="float: right;">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                        <input type="text" class="am-form-field" name="name"
                                               placeholder="请输入人员名称/手机号"
                                               value="<?= $request->get('name') ?>">
                                        <div class="am-input-group-btn">
                                            <button class="am-btn am-btn-default am-icon-search"
                                                    type="submit"></button>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    </div>

                <div class="am-u-sm-12">
                    <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
                        <thead>
                        <tr>
                            <th>人员ID</th>
                            <th>人员名称</th>
                            <th>登录名称</th>
                            <th>职位</th>
                            <th>操作端</th>
                            <th>上级名称</th>
                            <th>所属城市</th>
                            <th>所属区域</th>
                            <th>所属项目</th>
                            <th>添加时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php if (!$list->isEmpty()): foreach ($list as $item): ?>
                            <tr>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= $item['id'] ?></p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= $item['name'] ?></p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= $item['user_name'] ?></p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= types($item['type'])?></p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= ty($item['login_type']) ?></p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= upname($item['pid']) ?></p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= getName($item['cityid']) ?></p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= getName($item['areaid']) ?></p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= getbuild($item['loupanids']) ?></p>
                                </td>
                                <td class="am-text-middle"><?= gettimes($item['create_time']) ?></td>
                                <?php if ($userType==1): ?>
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <a href="<?= url('agent.agent/edit?user_id='.$item['id']) ?>">
                                                <i class="am-icon-pencil"></i> 编辑
                                            </a>
                                            <?php if ($item['is_delete']==0): ?>
                                                <a href="javascript:void(0);" class="j-delete tpl-table-black-operation-del"
                                                   data-id="<?= $item['id'] ?>">
                                                    <i class="am-icon-trash"></i> 删除
                                                </a>
                                            <?php endif; ?>
                                            <?php if ($item['is_delete']==1): ?>
                                                <a href="javascript:void(0);" class="j-active tpl-table-black-operation-add"
                                                   data-id="<?= $item['id'] ?>">
                                                    <i class="am-icon-trash"></i> 恢复
                                                </a>
                                            <?php endif; ?>
                                        </div>
                                    </td>
                                <?php endif; ?>
                                <?php if ($userType!=1): ?>
                                    <td class="am-text-middle">
                                        暂无权限
                                    </td>
                                <?php endif; ?>

                            </tr>
                        <?php endforeach; else: ?>
                            <tr>
                                <td colspan="4" class="am-text-center">暂无记录</td>
                            </tr>
                        <?php endif; ?>
                        </tbody>
                    </table>
                </div>
                <div class="am-u-lg-12 am-cf">
                    <div class="am-fr"><?= $list->render() ?> </div>
                    <div class="am-fr pagination-total am-margin-right">
                        <div class="am-vertical-align-middle">总记录：<?= $list->total() ?></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        // 激活
        var aurl = "<?= url('agent.agent/recover') ?>";
        $('.j-active').delete('userid', aurl, '确定要恢复吗？');

        // 删除元素
        var url = "<?= url('agent.agent/delete') ?>";
        $('.j-delete').delete('userid', url, '确定要删除吗？');

    });
</script>

